/**
 * @param {number[]} prices
 * @return {number}
 */
 var maxProfit = function (prices) {
    let end = 0
    let min = prices[0]
    prices.map(e => {
      if (e < min) {
        min = e
      }
      if (e - min > end) {
        end = e - min
      }
    }
    )
    return end
  };